//
//  HMMineHeaderView.m
//  欢乐美食
//
//  Created by MacOS on 15/7/11.
//  Copyright (c) 2015年 遇水. All rights reserved.
//

#import "HMMineHeaderView.h"
#import "HMMineHeader.h"
#import "HMMineHeaderFrame.h"
#import "UIImage+Extension.h"

@interface HMMineHeaderView()

@property (nonatomic, strong) UIButton *nameBack;
@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *nameLable;
@property (nonatomic, strong) UIImageView *arrowView;

@property (nonatomic, strong) UIView *coinBack;
@property (nonatomic, strong) UIImageView *coinView;
@property (nonatomic, strong) UILabel *coinLabel;
@property (nonatomic, strong) UILabel *coin;

@property (nonatomic, strong) UIButton *collectionBack;
@property (nonatomic, strong) UIImageView *collectionView;
@property (nonatomic, strong) UILabel *collectionLabel;
@property (nonatomic, strong) UILabel *collection;

@end

@implementation HMMineHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.userInteractionEnabled = YES;
        self.backgroundColor = [UIColor whiteColor];
        
        [self setupTopView];
        
        [self setupBottomView];
        
    }
    return self;
}

- (void)setupTopView
{
    // 用户名
    UIButton *nameBack = [[UIButton alloc] init];
    nameBack.backgroundColor = [UIColor whiteColor];
    [nameBack setBackgroundImage:[UIImage createImageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal];
    [nameBack setBackgroundImage:[UIImage createImageWithColor:[UIColor grayColor]] forState:UIControlStateHighlighted];
    [nameBack addTarget:self action:@selector(editUserInfo) forControlEvents:UIControlEventTouchUpInside];
    self.nameBack = nameBack;
    [self addSubview:nameBack];
    
    // 头像
    UIImageView *iconView = [[UIImageView alloc] init];
    self.iconView = iconView;
    [nameBack addSubview:iconView];
    // 名称
    UILabel *nameLable = [[UILabel alloc] init];
    nameLable.font = [UIFont systemFontOfSize:HMMineTextSizeFont];
    nameLable.textColor = [UIColor grayColor];
    self.nameLable = nameLable;
    [nameBack addSubview:nameLable];
    
    UIImageView *arrowView = [[UIImageView alloc] init];
    self.arrowView = arrowView;
    [nameBack addSubview:arrowView];
    
}

- (void)setupBottomView
{
    // 代金券
    UIView *coinBack = [[UIView alloc] init];
    [self addSubview:coinBack];
    coinBack.backgroundColor = HMColor(228, 239, 255);
    self.coinBack = coinBack;
    
    UIImageView *coinView = [[UIImageView alloc] init];
    self.coinView = coinView;
    [coinBack addSubview:coinView];
    
    UILabel *coinLabel = [[UILabel alloc] init];
    coinLabel.font = [UIFont systemFontOfSize:HMMineTextSizeFont];
    coinLabel.textColor = [UIColor grayColor];
    self.coinLabel = coinLabel;
    [coinBack addSubview:coinLabel];
    
    UILabel *coin = [[UILabel alloc] init];
    coin.font = [UIFont systemFontOfSize:HMMineTextSizeFont];
    coin.textColor = [UIColor grayColor];
    self.coin = coin;
    [coinBack addSubview:coin];
    
    
    // 我的收藏
    UIButton *collectionBack = [[UIButton alloc] init];
    [collectionBack setBackgroundImage:[UIImage createImageWithColor:HMColor(133, 225, 183)] forState:UIControlStateNormal];
    [collectionBack setBackgroundImage:[UIImage createImageWithColor:HMColor(53, 205, 136)] forState:UIControlStateHighlighted];
    [collectionBack addTarget:self action:@selector(editCollectionInfo) forControlEvents:UIControlEventTouchUpInside];
    self.collectionBack = collectionBack;
    [self addSubview:collectionBack];
    
    UIImageView *collectionView = [[UIImageView alloc] init];
    self.collectionView = collectionView;
    [collectionBack addSubview:collectionView];
    NSLog(@"collectionView=%d", self.collectionBack.subviews.count);
    
    UILabel *collectionLabel = [[UILabel alloc] init];
    collectionLabel.font = [UIFont systemFontOfSize:HMMineTextSizeFont];
    collectionLabel.textColor = [UIColor grayColor];
    self.collectionLabel = collectionLabel;
    [collectionBack addSubview:collectionLabel];
    
    UILabel *collection = [[UILabel alloc] init];
    collection.font = [UIFont systemFontOfSize:HMMineTextSizeFont];
    collection.textColor = [UIColor grayColor];
    self.collection = collection;
    [collectionBack addSubview:collection];
    
}

- (void)setHeaderFrame:(HMMineHeaderFrame *)headerFrame
{
    _headerFrame = headerFrame;
    HMMineHeader *headerData = headerFrame.headerData;
    
    self.iconView.image = [UIImage imageNamed:headerData.icon];
    self.iconView.frame = headerFrame.iconFrame;
    
    self.nameLable.text = headerData.userName;
    self.nameLable.frame = headerFrame.userNameFrame;
  
    self.arrowView.image = [UIImage imageNamed:@"icon_cell_rightArrow"];
    self.arrowView.frame = headerFrame.arrowFrame;
    
    self.nameBack.frame = headerFrame.nameBackFrame;
    
    // 代金券
    self.coinView.image = [UIImage imageNamed:headerData.coinIcon];
    self.coinView.frame = headerFrame.coinIconFrame;
    
    self.coinLabel.text = @"代金券";
    self.coinLabel.frame = headerFrame.coinLabelFrame;
    
    self.coin.text = headerData.coin;
    self.coin.frame = headerFrame.coinTextFrame;
    
    self.coinBack.frame = headerFrame.coinFrame;
    
    // 我的收藏
    self.collectionView.image = [UIImage imageNamed:headerData.collectionIcon];
    self.collectionView.frame = headerFrame.collectionIconFrame;
 
    self.collectionLabel.text = @"我的收藏";
    self.collectionLabel.frame = headerFrame.collectionLabelFrame;

    self.collection.text = headerData.collection;
    self.collection.frame = headerFrame.collectionTextFrame;
    
    self.collectionBack.frame = headerFrame.collectionFrame;

    self.frame = headerFrame.frame;
    
}

- (void)editUserInfo
{
    NSLog(@"editUserInfo");
}

- (void)editCollectionInfo
{
    NSLog(@"editCollectionInfo");
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
